/*
************************************
*       Module : callbase.h        *
*       Name   : TF                *
*       Date   : 06-03-2009        *
************************************
*/
#ifndef _CALLBASE_H_
#define _CALLBASE_H_

#include "common.h"

extern __pcs DWORD base_func0(DWORD a_func_no);
extern __pcs DWORD base_func1(DWORD a_func_no,DWORD a_param1);
extern __pcs DWORD base_func2(DWORD a_func_no,DWORD a_param1,DWORD a_param2);
extern __pcs DWORD base_func3(DWORD a_func_no,DWORD a_param1,DWORD a_param2,DWORD a_param3);

                /****** IP define ******/

#define K_IpALen                4       /* IP address length in bytes */
typedef unsigned long IPaddr;           /* internet address */

                /****** TCP func define ******/

#define K_TcpOpenMask           0x17
#define K_TcpOpenPppMode        0x01
#define K_TcpOpenNoCloseWait    0x02
#define K_TcpOpenSslMode        0x04
#define K_FtpOpenSslCmdMode     0x08  // for ftp func only
#define K_GprsOpenLargeMtu      0x10  // for gprs only
/*
  b_sslidx
    ssl key index
  b_option
    bit0 = PPP channel
    bit1 = set => no wait for tcp complete before allow re-connection
    bit2 = ssl mode
*/

// tcp status select to tcp status
#define K_TcpStatus             0
// tcp status to app
// bit 0-7
#define K_TcpIdleState          0
#define K_TcpConnectingState    1
#define K_TcpConnectedState     2
#define K_TcpClosingState       3
#define K_TcpClosedState        4
#define K_SslConnectedState     0x8000
#define K_TcpAlertState         0x4000

#define K_TcpTxBufSize          K_4BufSize

// tcp status select for tcp tx buffer left
#define K_TcpTxBufLeft          1

// tcp status select for tcp rx buffer use
#define K_TcpRxBufUsed          2

// tcp status select to tcb error status
#define K_TcpErrorStatus        3

// tcp status select to clear tx buffer
#define K_TcpTxBufClear         4

typedef struct {
  IPaddr  d_ip;   // ip stored in big endian
  WORD    w_port; // port stored in little endian or follow cpu
  BYTE    b_sslidx;
  BYTE    b_option;
} T_TCP_PORT;

                /****** UDP func define ******/

// udp status select to udp status
#define K_UdpStatus               0
// udp status to app
// bit 0-7
#define K_UdpIdleState            0
#define K_UdpConnectedState       1

typedef struct {
  IPaddr  d_ip;   // ip stored in big endian
  WORD    w_port; // port stored in little endian or follow cpu
  BYTE    b_mode;
} T_UDP_PORT;

#define K_UdpOpenServerMode   0x01
#define K_UdpOpenPppMode      0x80

// udp app interface
#if (__IAR_SYSTEMS_ICC__)
#pragma pack(1)
#endif
typedef struct  {                 /* datagram (not UDP) */
  IPaddr  d_xg_fip;               /* foreign host IP address */
  WORD    w_xg_fport;             /* foreign UDP port number */
  BYTE    s_xg_data[1];           /* K_UMaxLen maximum data to/from UDP */
}
#if (!__IAR_SYSTEMS_ICC__)
__attribute__((packed))
#endif
T_XGRAM;
#if (__IAR_SYSTEMS_ICC__)
#pragma pack()
#endif

#define K_XgramHLen           (2+K_IpALen)

                /****** CAKEY func define ******/

#define K_CaKeyUserIdx1        0xff
#define K_CaKeyUserIdx2        0xfe
#define K_CaKeyUserIdx3        0xfd
#define K_CaKeyUserIdx4        0xfc

                /****** ICMP func define ******/

#define K_IcmpPppMode         0x01

                /****** NIF func define ******/
#define K_MaxDns              2

typedef struct {
  IPaddr  d_ip;             // stored in big endian
  IPaddr  d_netmask;        // stored in big endian
  IPaddr  d_gateway;        // stored in big endian
  IPaddr  s_dns[K_MaxDns];  // stored in big endian
} T_NIF_INFO;

#define K_NIF_ETHERNET        0
#define K_NIF_PPP             1

                /****** Phone func define ******/

// phone detection status
#define   K_PhoneOnhook           0
#define   K_PhoneOffhook          1
#define   K_PhoneNoline           2
#define   K_PhoneDetectNotEnable  3

                /****** Call ID func define ******/
// mode
#define K_CidModeNone             0
#define K_CidModeUsa              1
#define K_CidModeUk               2
#define K_CidModeJapan            3

#define K_CidModeDisable          0
#define K_CidModeEnable           1

                /****** line dial func define ******/

typedef struct {
  BYTE b_protocol;               /* Default SDLC */
                                 /* 0 - Visa1 */
                                 /* 1 - SDLC  */
                                 /* 2 - Async */
  BYTE b_ccitt;                  /* 0 - Bell */
                                 /* 1 - CCITT */
                                 /* 2 - Hypercom Special 1200 */
  BYTE b_speed;                  /* 0 - 300bps */
                                 /* 1 - 1200bps */
                                 /* 2 - 2400bps */
                                 /* 3 - 9600bps */
                                 /* 4 - auto */
                                 /* 5 - auto with V.42 & MNP enable */
                                 /* 6 - auto with V.42 & MNP enable and using circular */
                                 /*     buffer supporting Unionpay STX message format in RX */
                                 /* 7 - 14400bps */
                                 /* 8 - 33600bps */
                                 /* 9 - 56000bps */
                                 /* bit 7 set for support Unionpay STX message format */
  BYTE b_inactivity_tval;        /* in unit of 2.5 sec */
  BYTE b_redial_pause_tval;      /* Pause time between redial in 100 msec*/
  BYTE b_ptel_len;               /* Primary telno length */
  BYTE s_ptel[66];               /* Prime telno */
  BYTE b_pconn_limit;            /* # of connection attempt */
  BYTE b_pconn_tval;             /* Time allowed to wait CD in 2 sec unit */
  BYTE b_stel_len;               /* Secondary telno length */
  BYTE s_stel[66];               /* Secondary telno */
  BYTE b_sconn_limit;            /* # of connection attempt */
  BYTE b_sconn_tval;             /* Time allowed to wait CD in 2 sec unit */
  BYTE b_cd_on_qualify_tval;     /* cd on qualify time in 0.25 sec,default 3 */
  BYTE b_cd_off_qualify_tval;    /* cd off qualify time in 0.25 sec,default 4 */
  BYTE b_message_qualify_tval;   /* Message qualify time in 10msec, default 10 */
  BYTE b_wait_online_tval;       /* wait for link online in sec, default 15 */
  BYTE b_tone_duration;          /* tone duration in 10msec */
  BYTE b_holdline_tval;          /* hold line time in second */
  BYTE b_detect_mode;            /* bit 0 - 0 = busy tone detection */
                                 /*         1 = disable busy tone detection */
                                 /* bit 1 - 0 = check line before dial */
                                 /*         1 = no check line */
                                 /* bit 2 - 0 = blind dialing disable */
                                 /*         1 = blind dialing enable */
                                 /* bit 3 - 0 = normal dial tone duration */
                                 /*         1 = short dial tone duration */
} T_LINE_CONFIG;

// b_ccitt
#define K_LineBell                0x00
#define K_LineCcitt               0x01
#define K_LineHypercomSpecial     0x02

// b_detect_mode
#define K_LineDisBusyToneDetect   0x01
#define K_LineNoCheckLine         0x02
#define K_LineBlindDial           0x04
#define K_LineShortDialTone       0x08
#define K_LineNoLoopCurrentDetect 0x10

// line status = dialing state + sticky status
// bit 0-7 - dialing state
#define K_LineIdle              0
#define K_LineDialingP1         1
#define K_LineDialingP2         2
#define K_LineConnectingP1      3
#define K_LineConnectingP2      4
#define K_LineHostConnected     5
#define K_LineCdLost            0x80
#define K_LineHostOffline       0x81
#define K_LineInactivityTimeout 0x82
#define K_LineConnectionFail    0x83
#define K_LineConnectTimeout    0x84

// sticky status, cleared after being read
#define K_LineOccupied          0x00000100
#define K_LineNoLine            0x00000200
#define K_LineNoDialTone        0x00000400
#define K_LineWrongNo           0x00000800
#define K_LineBusy              0x00001000
#define K_LineNoCd              0x00002000
#define K_LineConnectFail       0x00004000
#define K_LineMdmBusy           0x00008000
#define K_LineMsgTxed           0x00010000
#define K_LineWaitDisc          0x00020000
#define K_LineWaitDial          0x00040000

// line disc holdline
#define K_LineHoldLine          1
#define K_LineNoHoldLine        0

                /****** ppp func define ******/

#define K_PppDeviceGprs           1
#define K_PppDeviceAux1           2
#define K_PppDeviceAuxdbg         3
#define K_PppDeviceLine           4
#define K_PppDeviceOpenNeg        0x80
#define K_PppDeviceFixIp          0x40

// PPP mode
/* physical::type values (OR'd in bundle::phys_type) */
#define K_PppModeNone             0
#define K_PppModeInteractive      1   /* Manual link */
#define K_PppModeNormal           2
#define K_PppModeDirect           4   /* already established */
#define K_PppModeDDial            8   /* Dial immediately, stay connected */
#define K_PppModeAll              15

// ppp phase
#define K_PppIdle                 -1  /* idle not open and own by any owner */
#define K_PppPhaseDead            0   /* Link is dead */
#define K_PppPhaseEstablish       1   /* Establishing link */
#define K_PppPhaseAuthenticate    2   /* Being authenticated */
#define K_PppPhaseNetwork         3   /* We're alive ! */
#define K_PppPhaseTerminate       4   /* Terminating link */
#define K_PppPhaseReady           5   /* ppp is in a usable state */

/*
Expect-Send struct
It is possible to specify some special `values' in the expect-send script as follows:
  \c  When used as the last character in a `send' string, this indicates that a newline
      should not be appended.
  \d  When the chat script encounters this sequence, it delays two seconds.
  \p  When the chat script encounters this sequence, it delays for one quarter of a second.
  \T  This is replaced by the current phone number (see ``set phone'' below).
  \P  This is replaced by the current authkey value (see ``set authkey'' above).
  \U  This is replaced by the current authname value (see ``set authname'' above).
  \j<r1[r2][r3]...>  Reletive jump to other expect_send pair.
      if jump to the location grater than total expect-send, script done.
      if jump to location less than 0, script failed.
*/
// script contains "expect-send" pair strings for modem communication
typedef struct {
  char ** p_expect;     // expect receive strings, the last one must NULL
  WORD  w_min_len;      // min. expect len
  WORD  w_max_len;      // max. expect len
  signed char * p_send; // reply string
  char * p_abort;       // expect receive abort string
  short w_timeout;      // timeout for expect
  BYTE  b_retry;        // no. of retry
  char  b_flags;        // flags
} T_EXPECT_SEND;

#define K_DefaultScript       0xff    // use default script when no of pair = 0xff
#define K_GprsFixSpeed        460800

                /****** ftp func define ******/

// ftp status select ftp status
#define K_FtpStatus             0
// bit 7  = indicates ftp cmd Q is not empty
// bit0-6 = ftp status
#define K_FtpIdle               0
#define K_FtpConnecting         1
#define K_FtpConnected          2
#define K_FtpOpening            3
#define K_FtpOpened             4
#define K_FtpDataConnecting     5
#define K_FtpDataConnected      6
#define K_FtpClosing            7
// get back ftp control channel tcp status
#define K_FtpCtrlChnTcpStatus   1
// get back ftp data channel tcp status
#define K_FtpDataChnTcpStatus   2
// get back ftp control channel tcp tx buffer left
#define K_FtpCtrlChnTcpTxBufLeft  3
// get back ftp data channel tcp tx buffer left
#define K_FtpDataChnTcpTxBufLeft  4
// get back ftp control channel tcp rx buffer used
#define K_FtpCtrlChnTcpRxBufUsed  5
// get back ftp data channel tcp rx buffer used
#define K_FtpDataChnTcpRxBufUsed  6


                /****** udp & tcp open status define ******/
#define K_NoProcess               0xff


                /****** DNS define ******/
#define K_DnsDefaultPort          53
#define K_DnsMaxLen               100

typedef struct {
  BYTE    s_name[K_DnsMaxLen];
  IPaddr  d_ip;       // DNS server IP in big endian
  WORD    w_port;     // DNS server port in little endian
  WORD    w_timeout;  // response timeout in unit 10msec, 0 = default 1000 for 10sec
} T_DNS_REQ;

                /****** HTTP define ******/
#define K_HttpDefaultPort         80
#define K_HttpsDefaultPort        443

#define K_HttpVersion1_0          0
#define K_HttpVersion1_1          1

#define K_HttpGet                 0
#define K_HttpPost                1

#define K_HttpMaxHostLen          300
#define K_HttpMaxUriLen           300
#define K_HttpMaxDataLen          (K_2BufSize-100)

typedef struct {
  IPaddr  d_dns_ip;
  WORD    w_dns_port;
  WORD    w_host_port;
  BYTE    s_host[K_HttpMaxHostLen];
  BYTE    b_sslidx;   // same as tcp
  BYTE    b_option;   // same as tcp
  BYTE    b_version;  // http version
} T_HTTP_INFO;

typedef struct {
  WORD    w_req_len;
  BYTE    s_uri[K_HttpMaxUriLen];
  BYTE    b_method;
  BYTE    b_close;    // set pack close http connection at the end
  WORD    w_max_rlen; // max rx buffer length
  WORD    w_timeout;  // response timeout in unit 10msec, 0 = default 1000 for 10sec
} T_HTTP_REQ;

// http status select http status
#define K_HttpStatus              0
// bit0-7 = http status
#define K_HttpIdle                0
#define K_HttpOpened              1
#define K_HttpDnsResolve          2
#define K_HttpConnecting          3
#define K_HttpConnected           4
#define K_HttpRequested           5
#define K_HttpDisconnecting       6

                /****** base func routine ******/

#define   BS_FN_GET_VERSION       0
// void bs_get_version(BYTE * a_ptr);
#define bs_get_version(x)         base_func1(BS_FN_GET_VERSION,(DWORD)(x))

#define   BS_FN_TCP_OPEN          (BS_FN_GET_VERSION + 1)
// DWORD base_tcp_open(void);
#define bs_tcp_open()             base_func0(BS_FN_TCP_OPEN)

#define   BS_FN_TCP_CLOSE         (BS_FN_TCP_OPEN + 1)
// DWORD base_tcp_close(DWORD a_handle);
#define bs_tcp_close(x)           base_func1(BS_FN_TCP_CLOSE,(DWORD)(x))

#define   BS_FN_TCP_CONNECT       (BS_FN_TCP_CLOSE + 1)
// DWORD base_tcp_connect(DWORD a_handle,T_TCP_PORT * a_tcp);
#define bs_tcp_connect(x,y)       base_func2(BS_FN_TCP_CONNECT,(DWORD)(x),(DWORD)(y))

#define   BS_FN_TCP_DISCONNECT    (BS_FN_TCP_CONNECT + 1)
// DWORD base_tcp_disconnect(DWORD a_handle);
#define bs_tcp_disconnect(x)      base_func1(BS_FN_TCP_DISCONNECT,(DWORD)(x))

#define   BS_FN_TCP_SEND          (BS_FN_TCP_DISCONNECT + 1)
// DWORD base_tcp_send(DWORD a_handle,BYTE * a_buf,DWORD a_len);
#define bs_tcp_send(x,y,z)        base_func3(BS_FN_TCP_SEND,(DWORD)(x),(DWORD)(y),(DWORD)(z))

#define   BS_FN_TCP_READ          (BS_FN_TCP_SEND + 1)
// DWORD base_tcp_read(DWORD a_handle,BYTE * a_buf);
#define bs_tcp_read(x,y)          base_func2(BS_FN_TCP_READ,(DWORD)(x),(DWORD)(y))

#define   BS_FN_TCP_STATUS        (BS_FN_TCP_READ + 1)
// DWORD base_tcp_status(DWORD a_handle,DWOD a_select,T_TCP_PORT * a_tcp);
#define bs_tcp_status(x,y,z)      base_func3(BS_FN_TCP_STATUS,(DWORD)(x),(DWORD)(y),(DWORD)(z))

#define   BS_FN_UDP_OPEN          (BS_FN_TCP_STATUS + 1)
// DWORD base_udp_open(void);
#define bs_udp_open()             base_func0(BS_FN_UDP_OPEN)

#define   BS_FN_UDP_CLOSE         (BS_FN_UDP_OPEN + 1)
// DWORD base_udp_close(DWORD a_handle);
#define bs_udp_close(x)           base_func1(BS_FN_UDP_CLOSE,(DWORD)(x))

#define   BS_FN_UDP_CONNECT       (BS_FN_UDP_CLOSE + 1)
// DWORD base_udp_connect(DWORD a_handle,T_UDP_PORT * a_udp);
#define bs_udp_connect(x,y)       base_func2(BS_FN_UDP_CONNECT,(DWORD)(x),(DWORD)(y))

#define   BS_FN_UDP_DISCONNECT    (BS_FN_UDP_CONNECT + 1)
// DWORD base_udp_disconnect(DWORD a_handle);
#define bs_udp_disconnect(x)      base_func1(BS_FN_UDP_DISCONNECT,(DWORD)(x))

#define   BS_FN_UDP_SEND          (BS_FN_UDP_DISCONNECT + 1)
// DWORD base_udp_send(DWORD a_handle,BYTE * a_buf,DWORD a_len);
#define bs_udp_send(x,y,z)        base_func3(BS_FN_UDP_SEND,(DWORD)(x),(DWORD)(y),(DWORD)(z))

#define   BS_FN_UDP_READ          (BS_FN_UDP_SEND + 1)
// DWORD base_udp_read(DWORD a_handle,BYTE * a_buf);
#define bs_udp_read(x,y)          base_func2(BS_FN_UDP_READ,(DWORD)(x),(DWORD)(y))

#define   BS_FN_UDP_STATUS        (BS_FN_UDP_READ + 1)
// DWORD base_udp_status(DWORD a_handle,DWORD a_select);
#define bs_udp_status(x,y)        base_func2(BS_FN_UDP_STATUS,(DWORD)(x),(DWORD)(y))

#define   BS_FN_CAKEY_INJECT      (BS_FN_UDP_STATUS + 1)
// BOOLEAN base_cakey_inject(T_KEY * a_key);
#define bs_cakey_inject(x)        base_func1(BS_FN_CAKEY_INJECT,(DWORD)(x))

#define   BS_FN_ICMP_CONFIG       (BS_FN_CAKEY_INJECT + 1)
// DWORD base_icmp_config(DWORD a_ip,DWORD a_control)
// a_control
// bit 0 => PPP mode
#define bs_icmp_config(x,y)       base_func2(BS_FN_ICMP_CONFIG,(DWORD)(x),(DWORD)(y))

#define   BS_FN_ICMP_SEND         (BS_FN_ICMP_CONFIG + 1)
// DWORD base_icmp_send(DWORD a_ip,BYTE * a_buf,DWORD a_len)
#define bs_icmp_send(x,y,z)       base_func3(BS_FN_ICMP_SEND,(DWORD)(x),(DWORD)(y),(DWORD)(z))

#define   BS_FN_ICMP_READ         (BS_FN_ICMP_SEND + 1)
// DWORD base_icmp_read(BYTE * a_buf)
#define bs_icmp_read(x)           base_func1(BS_FN_ICMP_READ,(DWORD)(x))

#define   BS_FN_NET_NIF_INFO      (BS_FN_ICMP_READ + 1)
// DWORD base_net_nif_info(DWORD a_nif, T_NIF_INFO * a_pniff)
#define bs_net_nif_info(x,y)      base_func2(BS_FN_NET_NIF_INFO,(DWORD)(x),(DWORD)(y))

#define   BS_FN_PHONE_DETECT      (BS_FN_NET_NIF_INFO + 1)
// DWORD base_phone_detect(DWORD a_state); not support
#define bs_phone_detect(x)        base_func1(BS_FN_PHONE_DETECT,(DWORD)(x))

#define   BS_FN_PHONE_LINE        (BS_FN_PHONE_DETECT + 1)
//  DWORD base_phone_line(void); not support
#define bs_phone_line()           base_func0(BS_FN_PHONE_LINE)

#define   BS_FN_PHONE_DIAL        (BS_FN_PHONE_LINE + 1)
//  DWORD base_phone_dial(char * a_dial_str); not support
#define bs_phone_dial(x)          base_func1(BS_FN_PHONE_DIAL,(DWORD)(x))

#define   BS_FN_CID_DETECT        (BS_FN_PHONE_DIAL + 1)
//  DWORD base_cid_detect(DWORD a_mode); not support
#define bs_cid_detect(x)          base_func1(BS_FN_CID_DETECT,(DWORD)(x))

#define   BS_FN_CID_READ          (BS_FN_CID_DETECT + 1)
//  DWORD base_cid_read(BYTE * a_buf); min 64-byte buffer must be reserved, not support
#define bs_cid_read(x)            base_func1(BS_FN_CID_READ,(DWORD)(x))

#define   BS_FN_LINE_OPEN         (BS_FN_CID_READ + 1)
//  DWORD base_line_open(void); not support
#define bs_line_open()            base_func0(BS_FN_LINE_OPEN)

#define   BS_FN_LINE_CLOSE        (BS_FN_LINE_OPEN + 1)
//  void base_line_close(void); not support
#define bs_line_close()           base_func0(BS_FN_LINE_CLOSE)

#define   BS_FN_LINE_DIAL         (BS_FN_LINE_CLOSE + 1)
//  DWORD base_line_dial(T_LINE_CONFIG * a_pconfig); not support
#define bs_line_dial(x)           base_func1(BS_FN_LINE_DIAL,(DWORD)(x))

#define   BS_FN_LINE_DISC         (BS_FN_LINE_DIAL + 1)
//  DWORD base_line_disc(DWORD a_holdline); not support
#define bs_line_disc(x)           base_func1(BS_FN_LINE_DISC,(DWORD)(x))

#define   BS_FN_LINE_SEND         (BS_FN_LINE_DISC + 1)
//  DWORD base_line_send(BYTE * a_buf,DWORD a_len); not support
#define bs_line_send(x,y)         base_func2(BS_FN_LINE_SEND,(DWORD)(x),(DWORD)(y))

#define   BS_FN_LINE_READ         (BS_FN_LINE_SEND + 1)
//  DWORD base_line_read(BYTE * a_buf); not support
#define bs_line_read(x)           base_func1(BS_FN_LINE_READ,(DWORD)(x))

#define   BS_FN_LINE_STATUS       (BS_FN_LINE_READ + 1)
//  DWORD base_line_status(void); not support
#define bs_line_status()          base_func0(BS_FN_LINE_STATUS)

#define   BS_FN_PPP_OPEN          (BS_FN_LINE_STATUS + 1)
//  DWORD base_ppp_open(void);
#define bs_ppp_open()             base_func0(BS_FN_PPP_OPEN)

#define   BS_FN_PPP_CLOSE         (BS_FN_PPP_OPEN + 1)
//  void base_ppp_close(void);
#define bs_ppp_close()            base_func0(BS_FN_PPP_CLOSE)

#define   BS_FN_PPP_SET_DEVICE    (BS_FN_PPP_CLOSE + 1)
//  DWORD base_ppp_set_device(DWORD a_device,DWORD a_speed,DWORD a_id);
#define bs_ppp_set_device(x,y,z)  base_func3(BS_FN_PPP_SET_DEVICE,(DWORD)(x),(DWORD)(y),(DWORD)(z))

#define   BS_FN_PPP_SET_MTU       (BS_FN_PPP_SET_DEVICE + 1)
//  DWORD base_ppp_set_mtu(DWORD a_mtu);
#define bs_ppp_set_mtu(x)         base_func1(BS_FN_PPP_SET_MTU,(DWORD)(x))

#define   BS_FN_PPP_SET_MODE      (BS_FN_PPP_SET_MTU + 1)
//  DWORD base_ppp_set_mode(DWORD a_mode);
#define bs_ppp_set_mode(x)        base_func1(BS_FN_PPP_SET_MODE,(DWORD)(x))

#define   BS_FN_PPP_GET_SPEED     (BS_FN_PPP_SET_MODE + 1)
//  DWORD base_ppp_get_speed(void);
#define bs_ppp_get_speed()        base_func0(BS_FN_PPP_GET_SPEED)

#define   BS_FN_PPP_SET_SPEED     (BS_FN_PPP_GET_SPEED + 1)
//  void base_ppp_set_speed(DWORD a_sp);
#define bs_ppp_set_speed(x)       base_func1(BS_FN_PPP_SET_SPEED,(DWORD)(x))

#define   BS_FN_PPP_GET_PHASE     (BS_FN_PPP_SET_SPEED + 1)
//  DWORD base_ppp_get_phase(void);
#define bs_ppp_get_phase()        base_func0(BS_FN_PPP_GET_PHASE)

#define   BS_FN_PPP_SET_LOGIN_ID  (BS_FN_PPP_GET_PHASE + 1)
//  DWORD base_ppp_set_login_id(char * a_u,char * a_p);
#define bs_ppp_set_login_id(x,y)  base_func2(BS_FN_PPP_SET_LOGIN_ID,(DWORD)(x),(DWORD)(y))

#define   BS_FN_PPP_SET_DIAL_SC   (BS_FN_PPP_SET_LOGIN_ID + 1)
//  DWORD base_ppp_set_dialup_script(T_EXPECT_SEND * a_es,DWORD a_n);
#define bs_ppp_set_dialup_script(x,y) base_func2(BS_FN_PPP_SET_DIAL_SC,(DWORD)(x),(DWORD)(y))

#define   BS_FN_PPP_SET_ID_STR    (BS_FN_PPP_SET_DIAL_SC + 1)
//  DWORD base_ppp_set_id_str(char * a_id);
#define bs_ppp_set_id_str(x)        base_func1(BS_FN_PPP_SET_ID_STR,(DWORD)(x))

#define   BS_FN_PPP_SET_LOGIN_SCRIPT (BS_FN_PPP_SET_ID_STR + 1)
//  DWORD base_ppp_set_login_script(T_EXPECT_SEND * a_es,DWORD a_n);
#define bs_ppp_set_login_script(x,y) base_func2(BS_FN_PPP_SET_LOGIN_SCRIPT,(DWORD)(x),(DWORD)(y))

#define   BS_FN_PPP_SET_PHONES      (BS_FN_PPP_SET_LOGIN_SCRIPT + 1)
//  DWORD base_ppp_set_phones(char * a_p1,char * a_p2); not support
#define bs_ppp_set_phones(x,y)      base_func2(BS_FN_PPP_SET_PHONES,(DWORD)(x),(DWORD)(y))

#define   BS_FN_PPP_SET_DIAL_PARAM  (BS_FN_PPP_SET_PHONES + 1)
//  DWORD base_ppp_set_dial_param(T_LINE_CONFIG * a_dp); not support
#define bs_ppp_set_dial_param(x)    base_func1(BS_FN_PPP_SET_DIAL_PARAM,(DWORD)(x))

#define   BS_FN_PPP_SET_REDIAL      (BS_FN_PPP_SET_DIAL_PARAM + 1)
//  DWORD base_ppp_set_redial(DWORD * a_redial);
#define bs_ppp_set_redial(x)        base_func1(BS_FN_PPP_SET_REDIAL,(DWORD)(x))

#define   BS_FN_PPP_SET_RECONNECT   (BS_FN_PPP_SET_REDIAL + 1)
//  DWORD base_ppp_set_reconnect(DWORD a_timewait,DWORD a_retry);
#define bs_ppp_set_reconnect(x,y)   base_func2(BS_FN_PPP_SET_RECONNECT,(DWORD)(x),(DWORD)(y))

#define   BS_FN_PPP_LOGIN_READ      (BS_FN_PPP_SET_RECONNECT + 1)
//  DWORD base_ppp_login_read(char * a_buf,DWORD a_buf_size);
#define bs_ppp_login_read(x,y)      base_func2(BS_FN_PPP_LOGIN_READ,(DWORD)(x),(DWORD)(y))

#define   BS_FN_PPP_LOGIN_WRITE     (BS_FN_PPP_LOGIN_READ + 1)
//  DWORD base_ppp_login_write(char * a_buf,DWORD a_buf_size);
#define bs_ppp_login_write(x,y)     base_func2(BS_FN_PPP_LOGIN_WRITE,(DWORD)(x),(DWORD)(y))

#define   BS_FN_PPP_LOGIN_FINISH    (BS_FN_PPP_LOGIN_WRITE + 1)
//  DWORD base_ppp_login_finish(DWORD a_success);
#define bs_ppp_login_finish(x)      base_func1(BS_FN_PPP_LOGIN_FINISH,(DWORD)(x))

#define   BS_FN_PPP_SET_TIMEOUT     (BS_FN_PPP_LOGIN_FINISH + 1)
//  DWORD base_ppp_set_timeout(DWORD a_timeout,DWORD a_min_up);
#define bs_ppp_set_timeout(x,y)     base_func2(BS_FN_PPP_SET_TIMEOUT,(DWORD)(x),(DWORD)(y))

#define   BS_FN_PPP_UPTIME          (BS_FN_PPP_SET_TIMEOUT + 1)
//  DWORD base_ppp_uptime(void);
#define bs_ppp_uptime()             base_func0(BS_FN_PPP_UPTIME)

#define   BS_FN_PPP_SET_ALIVE_TIME (BS_FN_PPP_UPTIME + 1)
//  void base_ppp_set_alive_time(DWORD a_time);
#define bs_ppp_set_alive_time(x)   base_func1(BS_FN_PPP_SET_ALIVE_TIME,(DWORD)(x))

// bit 0-6 = device set
// bit 7 = 0 => PPP closed
//         1 => PPP opened
#define   BS_FN_PPP_GET_STATUS    (BS_FN_PPP_SET_ALIVE_TIME + 1)
//  DWORD base_ppp_get_status(void);
#define bs_ppp_get_status()       base_func0(BS_FN_PPP_GET_STATUS)

#define   BS_FN_FTP_OPEN          (BS_FN_PPP_GET_STATUS + 1)
//  DWORD base_ftp_open(void);
#define bs_ftp_open()             base_func0(BS_FN_FTP_OPEN)

#define   BS_FN_FTP_CLOSE         (BS_FN_FTP_OPEN + 1)
//  DWORD base_ftp_close(void);
#define bs_ftp_close()            base_func0(BS_FN_FTP_CLOSE)

#define K_FtpDataChannel          0
#define K_FtpCmdChannel           1
#define   BS_FN_FTP_CONNECT       (BS_FN_FTP_CLOSE + 1)
//  DWORD base_ftp_connect(T_TCP_PORT * a_tcp);
#define bs_ftp_connect(x)         base_func1(BS_FN_FTP_CONNECT,(DWORD)(x))

#define   BS_FN_FTP_DISCONNECT    (BS_FN_FTP_CONNECT + 1)
//  DWORD base_ftp_disconnect(DWORD a_which);
#define bs_ftp_disconnect(x)      base_func1(BS_FN_FTP_DISCONNECT,(DWORD)(x))

#define   BS_FN_FTP_DATA_SEND     (BS_FN_FTP_DISCONNECT + 1)
//  DWORD base_ftp_data_send(BYTE * a_buf,DWORD a_len);
#define bs_ftp_data_send(x,y)     base_func2(BS_FN_FTP_DATA_SEND,(DWORD)(x),(DWORD)(y))

#define   BS_FN_FTP_DATA_READ     (BS_FN_FTP_DATA_SEND + 1)
//  DWORD base_ftp_data_read(BYTE * a_buf);
#define bs_ftp_data_read(x)       base_func1(BS_FN_FTP_DATA_READ,(DWORD)(x))

#define   BS_FN_FTP_CMD_SEND      (BS_FN_FTP_DATA_READ + 1)
//  DWORD base_ftp_cmd_send(BYTE * a_str);
#define bs_ftp_cmd_send(x)        base_func1(BS_FN_FTP_CMD_SEND,(DWORD)(x))

#define   BS_FN_FTP_CMD_READ      (BS_FN_FTP_CMD_SEND + 1)
//  DWORD base_ftp_cmd_read(BYTE * a_buf);
#define bs_ftp_cmd_read(x)        base_func1(BS_FN_FTP_CMD_READ,(DWORD)(x))

#define   BS_FN_FTP_STATUS        (BS_FN_FTP_CMD_READ + 1)
//  DWORD base_ftp_status(DWORD a_select);
#define bs_ftp_status(x)          base_func1(BS_FN_FTP_STATUS,(DWORD)(x))

#define   BS_FN_LAN_OPEN          (BS_FN_FTP_STATUS + 1)
//  DWORD base_lan_open(void);
#define bs_lan_open()             base_func0(BS_FN_LAN_OPEN)

#define   BS_FN_LAN_CLOSE         (BS_FN_LAN_OPEN + 1)
//  void base_lan_close(void);
#define bs_lan_close()            base_func0(BS_FN_LAN_CLOSE)

#define K_BsLanStatus             0
#define K_LanPlugIn               0x01
#define K_LanEnabled              0x02
#define K_LanInstalled            0x04
#define   BS_FN_LAN_STATUS        (BS_FN_LAN_CLOSE + 1)
//  DWORD base_lan_status(DWORD a_select);
#define bs_lan_status(x)          base_func1(BS_FN_LAN_STATUS,(DWORD)(x))

#define   BS_FN_DNS_OPEN          (BS_FN_LAN_STATUS + 1)
//  DWORD base_dns_open(void);
#define bs_dns_open()             base_func0(BS_FN_DNS_OPEN)

#define   BS_FN_DNS_CLOSE         (BS_FN_DNS_OPEN + 1)
//  DWORD base_dns_close(void);
#define bs_dns_close()            base_func0(BS_FN_DNS_CLOSE)

#define   BS_FN_DNS_REQUEST       (BS_FN_DNS_CLOSE + 1)
//  DWORD base_dns_request(T_DNS_REQ * a_req);
#define bs_dns_request(x)         base_func1(BS_FN_DNS_REQUEST,(DWORD)(x))

#define   BS_FN_DNS_RESPONSE      (BS_FN_DNS_REQUEST + 1)
//  DWORD base_dns_response(void);
#define bs_dns_response()         base_func0(BS_FN_DNS_RESPONSE)
// 0.0.0.0 = no response
// 255.255.255.255 = response timeout
// other = response

#define   BS_FN_HTTP_OPEN         (BS_FN_DNS_RESPONSE + 1)
//  DWORD base_http_open(void);
#define bs_http_open()            base_func0(BS_FN_HTTP_OPEN)

#define   BS_FN_HTTP_CLOSE        (BS_FN_HTTP_OPEN + 1)
//  DWORD base_http_close(void);
#define bs_http_close()           base_func0(BS_FN_HTTP_CLOSE)

#define   BS_FN_HTTP_CONNECT      (BS_FN_HTTP_CLOSE + 1)
//  DWORD base_http_connect(T_HTTP_INFO *a_http_info);
#define bs_http_connect(x)        base_func1(BS_FN_HTTP_CONNECT,(DWORD)(x))

#define   BS_FN_HTTP_DISCONNECT   (BS_FN_HTTP_CONNECT + 1)
//  DWORD base_http_disconnect(void);
#define bs_http_disconnect()      base_func0(BS_FN_HTTP_DISCONNECT)

#define   BS_FN_HTTP_REQUEST      (BS_FN_HTTP_DISCONNECT + 1)
//  DWORD base_http_request(T_HTTP_REQ *a_request,BYTE *a_data,BYTE *a_response);
#define bs_http_request(x,y,z)      base_func3(BS_FN_HTTP_REQUEST,(DWORD)(x),(DWORD)(y),(DWORD)(z))

#define   BS_FN_HTTP_RESPONSE     (BS_FN_HTTP_REQUEST + 1)
//  DWORD base_http_response(void);
#define bs_http_response()       base_func0(BS_FN_HTTP_RESPONSE)
// 0 = no response
// -1 = timeout
// other = response length

#define   BS_FN_HTTP_STATUS       (BS_FN_HTTP_RESPONSE + 1)
//  DWORD base_http_status(DWORD a_select);
#define bs_http_status(x)         base_func1(BS_FN_HTTP_STATUS,(DWORD)(x))

#endif
